package com.yl.applicationsecurity.controller;

import com.github.pagehelper.PageInfo;
import com.yl.applicationsecurity.pojo.ApplicationCoverage;
import com.yl.applicationsecurity.pojo.RadarVulnerability;
import com.yl.applicationsecurity.pojo.Result;
import com.yl.applicationsecurity.service.RadarVulnerabilityService;
import com.yl.applicationsecurity.service.TodoListService;
import com.yl.applicationsecurity.utils.ExcelExportUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*;

/**
 * @author 鹤仙问鹿仙
 * @program: Application-security
 * @description:
 * @date 2025-02-19 16:35:32
 */
@RestController
@RequestMapping("/todoList")
public class TodoListController {


    @Autowired
    private TodoListService todoListService;

    @PostMapping("/getData")
    public Result list(String[] nationSelect){

        Map map = todoListService.getData(nationSelect);

        return Result.success(map);
    }


    @GetMapping("/export")
    public ResponseEntity<byte[]> exportExcel(HttpServletResponse response) throws IOException {

        List<Map> list =   todoListService.getExportDate();

        // 表头
        List<String> headers = Arrays.asList("负责人", "待处理交互逻辑探针-越权告警", "待处理交互逻辑探针-其他告警", "待处理登录入口巡检告警","待处理组件未授权扫描告警","待处理安全雷达告警");

        // 数据列映射
        List<String> columns = Arrays.asList("name", "sgmSafeRiskToBeProcessedCount", "sgmOtherVulnerabilityToBeProcessedCount", "inspectionToBeProcessedCount"
                , "componentUnauthorizedToBeProcessedCount" ,"radarVulnerabilityToBeProcessedCount");

        // 调用工具类进行导出
        ByteArrayOutputStream excelStream = ExcelExportUtil.exportToTodoLisrExcel(list, headers, columns);

        HttpHeaders headersResponse = new HttpHeaders();
        headersResponse.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=首页数据.xlsx");



        // 返回Excel文件（作为二进制流）
        byte[] excelFile = excelStream.toByteArray();

        HttpHeaders headers2 = new HttpHeaders();
        headersResponse.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=首页数据.xlsx");

        return ResponseEntity.ok()
                .headers(headers2)
                .contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
                .body(excelFile);
    }




}

